<template>
  <div>
    <h1>图片上传示例</h1>

    <el-upload
      class="avatar-uploader"
      :action="uploadUrl"
      :show-file-list="false"
      :on-success="handleAvatarSuccess"
      :before-upload="beforeAvatarUpload"
    >
      <img v-if="imageUrl" :src="imageUrl" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>

    <el-row>
      <el-button type="success" @click="downLoad()">一键下载</el-button>
    </el-row>
  </div>
</template>
 <style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<script>
import ElementUI from "element-ui";
import axios from "axios";
export default {
  data() {
    return {
      imageUrl: "",
      uploadUrl:
        "https://servicedev.youedian.cn/api/system/aliyunoss/upload?moduleStr=product&materialCode=12",
      //"http://localhost:44341/api/system/aliyunoss/upload?moduleStr=product&materialCode=12"
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG 格式!');
      // }
      // if (!isLt2M) {
      //   this.$message.error('上传头像图片大小不能超过 2MB!');
      // }
      // return isJPG && isLt2M;
      // var url=`https://systemadev.youedian.cn/api/system/aliyunoss/download?ids=${ids}`;
      // var url=`http://localhost:44341/api/system/aliyunoss/download?ids=${ids}`;
    },
    downLoad() {
      var s = {
        学制时间: "2.5年",
        学制期数: "5期",
        学习中心: "复测渠道",
        批次: "2021春季",
        考点: null,
        所需材料: "身份证反面",
      };
      for (var key in s) {
        console.log(key,s[key]);
      }

      // var ids="668BCA16-139E-3BAA-7CAD-39FD62BC1181";
      // var url=`https://servicedev.youedian.cn/api/system/aliyunoss/download?ids=${ids}`;
      // //var url=`http://localhost:44341/api/system/aliyunoss/download?ids=${ids}`;
      // window.open(url,"_blank");
    },
  },
};
</script>
